package 因子和.四因数;

import java.util.Arrays;

/**
 * TODO
 *
 * @className: sys
 * @description: TODO
 * @author: 等什么柠檬君
 * @date: 2022-05-08 11:19
 **/
public class sys {
    public static void main(String[] args) {
//        int[] nums = {21,4,7};
//        int[] nums = {21,21};
        int[] nums = {1,2,3,4,5};
        System.out.println(sumFourDivisors(nums));
    }
    static int[] primays = new int[100000+1];
    static boolean[] f = new boolean[100000+1];
    public static int sumFourDivisors(int[] nums) {

        initPrimay();
//        System.out.println(Arrays.toString(primays));
//        System.out.println(Arrays.toString(f));
//        System.out.println(isPrimay(2));

        System.out.println("当前共有素数 "+primays[0]+" 个");
        int count = 0,p = 0,q = 0,j = 1;
        for (int i = 0; i < nums.length; ++i) {
            System.out.println("当前计算 "+nums[i]+" 的四因子和");
            for (j = 1; j <= primays[0]; ++j) {
                 p = primays[j];
                if (nums[i] % p == 0){
                    System.out.println("当前计算 "+nums[i]+" 被 素数 "+p+" 整除");
                    q = nums[i] / p;
                    if (isPrimay(q) && q != p){
                        count += (p+1)*(q+1);
                    }
                    if (q == p * p){
                        count += p*p*p + p*p +p + 1;
                    }
                    break;
                }
            }

        }
        return count;
    }
    public static boolean isPrimay(int num){
        return !f[num];
    }
    public static void initPrimay(){
        f[0] = f[1] = true;
        primays[0] = 0;
        for (int i = 2; i <= 100000; i++) {
            if (!f[i]){
                primays[++primays[0]] = i;
                for (int j = i+i; j <= 100000 ; j += i) {
                    f[j] = true;
                }
            }
        }
    }
}
